package com.xzzz.backend.bsms.loadbalancer;

import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author wangyf
 * @ignore
 */
@RestController
@RequestMapping("/lb")
public class LBController {

    @Autowired
    private SimpleMeterRegistry simpleMeterRegistry;

    @GetMapping("/active")
    public double test() {
//        Search search = simpleMeterRegistry.find("loadbalancer.requests.active");
//        for (Gauge counter : search.gauges()) {
//            System.out.println(counter.value());
//        }

        Timer timer = simpleMeterRegistry.timer("loadbalancer.requests.success", "serviceId", "backend-bsms");
        return timer.totalTime(TimeUnit.NANOSECONDS);
    }
}
